package NetworkCopy.NIO;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class ClientNIO {
    public static void main(String[] args) throws IOException {
        String host = "localhost";

        try (
                SocketChannel socketChannel = SocketChannel.open();
                FileChannel inputChannel = new FileInputStream("data.bin").getChannel()) {

            socketChannel.connect(new InetSocketAddress(host, 7002));

            long start = System.currentTimeMillis();

            ByteBuffer buf = ByteBuffer.allocate(104857600);
            while (inputChannel.read(buf) >= 0){
                buf.flip();
                socketChannel.write(buf);
                buf.clear();
            }

            long end = System.currentTimeMillis();
            System.out.println("Time: " + (end - start) + " ms");
        }
    }
}
